// variable_argument_lists.cpp
#include <stdio.h>
#include <stdarg.h>
#include<iostream>
#include<exception>
#include<string>
#include <stdio.h>

using namespace std;

//  Declaration, but not definition, of ShowVar.
void ShowVar(int iother, char *szTypes, ... );
/*
int main() {
   //ShowVar(6, "b", 4545454545454545456 );


	char* fullFilePath; // = (char*)malloc(1000);
	size_t chunkIndex = 1234567891234;
	sprintf(fullFilePath, "%zu", chunkIndex);

	cout << fullFilePath << endl;
		return 0;

}
*/

//  ShowVar takes a format string of the form
//   "ifcs", where each character specifies the
//   type of the argument in that position.
//
//  i = int
//  f = float
//  c = char
//  s = string (char *)
//
//  Following the format specification is a list
//  of n arguments, where n == strlen( szTypes ).
void ShowVar(int iother, char *szTypes, ... ) {
   va_list vl;
   int i;

   printf("%d\n", iother);

   //  szTypes is the last argument specified; all
   //   others must be accessed using the variable-
   //   argument macros.
   va_start( vl, szTypes );

   // Step through the list.
   for( i = 0; szTypes[i] != '\0'; ++i ) {
      union Printable_t {
         int     i;
         float   f;
         size_t  bi;
         char   *s;
      } Printable;

      char *msg;

      switch( szTypes[i] ) {   // Type to expect.
         case 'i':
            Printable.i = va_arg( vl, int );
            printf("%i\n", Printable.i );
            //cout<<msg;
         break;

         case 'f':
             Printable.f = va_arg( vl, double );
             printf("%f\n", Printable.f );
             //cout<<msg;
         break;

         case 'b':
        	 Printable.bi = va_arg( vl, size_t );
        	 printf("%llu\n", Printable.bi );
        	 //cout<<msg;
		 break;

         case 's':
             Printable.s = va_arg( vl, char * );
             printf("%s\n", Printable.s );
             //cout<<msg;
         break;

         default:
         break;
      }
   }
   va_end( vl );
}
